﻿/*
 * 
 *	C# object representation of row in 'researchRepo.users' table:
 *	
 *	Currently a simple mapping of all table columns to equivalent properties,
 *	though the class might be expanded to track appropriate relationships with other tables.
 * 
 */

namespace ResearchRepository.Models
{
	public class RRUser
	{
		public RRUser(int uID, string uName, string uPass, int unID, int dID, string fName, string mName, string lName, string pre, string post)
		{
			UserID = uID;
			UserName = uName;
			UserPass = uPass;
			UnivID = unID;
			DeptID = dID;
			FirstName = fName;
			MiddleName = mName;
			LastName = lName;
			PreTitles = pre;
			PostTitles = post;
		}
		public RRUser(RRUser source)
			:this(source.UserID,
					source.UserName,
					source.UserPass,
					source.UnivID,
					source.DeptID,
					source.FirstName,
					source.MiddleName,
					source.LastName,
					source.PreTitles,
					source.PostTitles)
		{}
		public RRUser(System.Data.IDataRecord source)
			:this((int) source["userID"],
					(string) source["userName"],
					(string) source["userPass"],
					source["univID"] != System.DBNull.Value ? (int) source["univID"] : 0,	// univID may be NULL
					source["deptID"] != System.DBNull.Value ? (int) source["deptID"] : 0,	// deptID may be NULL
					(string) source["firstName"],
					(string) source["middleName"],
					(string) source["lastName"],
					(string) source["preTitles"],
					(string) source["postTitles"])
		{}

		// named alias for constructor, provides handle to simulate a function pointer to constructor
		public static RRUser construct(System.Data.IDataRecord source)
		{
			return new RRUser(source);
		}
		// sentinel value to denote guest user for functions which require userID
			// since 0 is not allowed in an auto-incremented column in MySQL, it is an acceptable sentinel to denote 'none-of-the-above';
			// thus, even though 'guest' has an actual entry in the 'users' table with some userID!=0, it is not necessary to know that userID
		public const int GuestUserID = 0;

		public int UserID { get; set; }
		public string UserName { get; set; }
		public string UserPass { get; set; }
		public int UnivID { get; set; }
		public int DeptID { get; set; }
		public string FirstName { get; set; }
		public string MiddleName { get; set; }
		public string LastName { get; set; }
		public string PreTitles { get; set; }
		public string PostTitles { get; set; }

		public string FullName
		{
			get
			{
				return (PreTitles != "" ? PreTitles + " " : "")
						+ FirstName + " "
						+ (MiddleName != "" ? MiddleName + " " : "")
						+ LastName
						+ (PostTitles != "" ? ", " + PostTitles : "");
			}
		}
	}
}